<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>汽车之家</h1>
        <p>
            品牌：<input v-model="carInfo.brand"  type="text">
        </p>
        <p>
            系列：<input v-model="carInfo.series" type="text">
        </p>
        <p>
            年份：<input v-model="carInfo.year" type="text">
        </p>

        <ul>
            <li v-for = "(item,index) in carList">
                {{item.brand}} - {{item.series}} - {{item.year}}
            </li>
        </ul>

    </div>
    

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el:"#app",
            data:{
                carInfo: {
                brand: "",
                series: "",
                year: ""
            },
            carList: [
                {
                    brand: "奥迪",
                    series: "奥迪A4",
                    year: "2021"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A4",
                    year: "2020"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A4",
                    year: "2019"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A6",
                    year: "2021"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A6",
                    year: "2020"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A6",
                    year: "2019"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A8",
                    year: "2019"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A8",
                    year: "2020"
                },
                {
                    brand: "奥迪",
                    series: "奥迪A8",
                    year: "2021"
                },
                {
                    brand: "奔驰",
                    series: "奔驰C180",
                    year: "2021"
                },
                {
                    brand: "奔驰",
                    series: "奔驰C180",
                    year: "2020"
                },
                {
                    brand: "奔驰",
                    series: "奔驰C180",
                    year: "2019"
                },
                {
                    brand: "奔驰",
                    series: "奔驰E300",
                    year: "2021"
                },
                {
                    brand: "奔驰",
                    series: "奔驰E300",
                    year: "2020"
                },
                {
                    brand: "奔驰",
                    series: "奔驰E300",
                    year: "2019"
                },
                {
                    brand: "奔驰",
                    series: "奔驰S500",
                    year: "2019"
                },
                {
                    brand: "奔驰",
                    series: "奔驰S500",
                    year: "2020"
                },
                {
                    brand: "奔驰",
                    series: "奔驰S500",
                    year: "2021"
                }
            ]


            },
            watch: {
                carInfo: {
                    deep: true,
                    handler(newValue, oldValue) {
                        // filter 会返回新的数组，所以要赋值
                        this.carList = this.carList.filter(item => {
                            return item.brand.includes(newValue.brand) && item.series.includes(newValue.series) && item.year.includes(newValue.year)
                    })
                    }
                }
            }
        })
    </script>
</body>
</html>